﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BdClient;

namespace Univer
{
    public partial class MainForm : Form
    {

        private readonly BdExecute _execute;
        AvailableCarsForm carsForm;
        ClientForm clientForm;
        AddNewCarForm addNewCarForm;
        TransactionForm transactionForm;
        TransactionsForm transactionsForm;
        CarsForm allCarsForm;
        ClientsForm clientsForm;

        public MainForm()
        {
            InitializeComponent();
            _execute= new BdExecute();
            Manager.getInstance().mainFormCallback = this;
        }

        public void updateClientInfo()
        {
            label6.Text = Manager.getInstance().result.id.ToString();
            checkTransactionButtonEnabled();
            button1.Enabled = true;
        }

        public void updateCarInfo()
        {
            label4.Text = Manager.getInstance().selectedCar.name;
            checkTransactionButtonEnabled();
            
        }

        public void updateFine()
        {
            checkTransactionButtonEnabled();
        }

        public void checkTransactionButtonEnabled()
        {
            if (Manager.getInstance().result == null ||
                 Manager.getInstance().selectedCar == null ||
                 Manager.getInstance().fineRequest == -1)
            {
                button3.Enabled = false;
            }
            else
            {
                button3.Enabled = true;
            }
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var cars = _execute.GetCars();
            carsForm = new AvailableCarsForm();
            carsForm.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            clientForm = new ClientForm();
            clientForm.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            addNewCarForm = new AddNewCarForm();
            addNewCarForm.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            transactionForm = new TransactionForm();
            transactionForm.Show();
        }

        private void button6_Click(object sender, EventArgs e)
        {
                transactionsForm = new TransactionsForm();
                transactionsForm.Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            allCarsForm = new CarsForm();
            allCarsForm.Show();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            clientsForm = new ClientsForm();
            clientsForm.Show();
        }
    }
}
